package com.sun;

import com.sun.model.WeiboException;
import com.sun.util.BareBonesBrowserLaunch;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @Description
 * @Author: zhaodongchao
 * @Company: datong
 * @Date: 2018-09-04
 * @Email: zhaodc@dtinsure.com
 */
public class MainTest{


    public static void main(String[] args)throws Exception {
        Oauth oauth = new Oauth();
        BareBonesBrowserLaunch.openURL(oauth.authorize("code"));
        System.out.println(oauth.authorize("code"));
        System.out.print("Hit enter when it's done.[Enter]:");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String code = br.readLine();
        System.out.println("code: " + code);
        try{
            System.out.println(oauth.getAccessTokenByCode(code));
        } catch (WeiboException e) {
            if(401 == e.getStatusCode()){
                System.out.println("Unable to get the access token.");
            }else{
                e.printStackTrace();
            }
        }
    }
}
